package cn.gson.work.controller;

import cn.gson.work.model.pojos.Dossier;
import cn.gson.work.model.service.DossierService;
import cn.gson.work.model.service.TrecordService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class DossierController {
    @Autowired
    DossierService dos;
    @Autowired
    TrecordService trs;

    /**
     * 分页条件模糊查询
     * @param page
     * @param size
     * @param rsid
     * @param rsname
     * @param rstate
     * @return
     */
    @RequestMapping("/findDossier")
    @ResponseBody
    public Map<String, Object> findVolume(@RequestParam("page") Integer page,
                                          @RequestParam("size") Integer size,
                                          @RequestParam("rsid") String rsid,
                                          @RequestParam("rsname") String rsname,
                                          @RequestParam("rstate") String rstate){
        Page<Object> obj= PageHelper.startPage(page, size);
        dos.findDossier(rsid,rsname,rstate);
        Map<String,Object> map =new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",obj.getResult());
        return map;
    }

    /**
     * 添加实体数据
     * @param dossier
     */
    @RequestMapping("/addDossier")
    @ResponseBody
    public void addDossier(@RequestBody Dossier dossier){
        dos.addDossier(dossier);
    }

    /**
     * 通过编号修改状态
     * @param rstate
     * @param rsno
     */
    @RequestMapping("/editDossier")
    @ResponseBody
    public void editDossier(@RequestParam("rstate") String rstate,@RequestParam("rsno") long rsno){
        dos.editDossier(rstate,rsno);
    }

    /**
     * 通过编号删除
     * @param id
     * @return
     */
    @RequestMapping("/delDossier")
    @ResponseBody
    public int delDossier(@RequestParam("id") int id){
        return dos.delDossier(id);
    }

    /**
     * 查询所有，在文件添加时调用（未数据重复校验）
     * @return
     */
    @RequestMapping("/findDossierAll")
    @ResponseBody
    public List<Dossier> findDossierAll(){
        return dos.findDossierAll();
    }

}
